namespace System.Linq.Reactive
{
    class WhereLamdaObservableEx<T> : IObservableEx<T>
    {
        private readonly IObserverEx<T> f_SourceObserver;
        private readonly Func<T, bool> f_WhereSelector;

        public WhereLamdaObservableEx(IObserverEx<T> observer, Func<T, bool> WhereSelector)
        {
            f_SourceObserver = observer;
            f_WhereSelector = WhereSelector;
        }

        public IObserverEx<T> GetObserver()
        {
            var observer = new SimpleObserverEx<T>();
            f_SourceObserver.Reset += observer.OnReset;
            f_SourceObserver.Exception += observer.OnException;
            f_SourceObserver.Complited += observer.OnComplited;
            f_SourceObserver.Next += item => { if(f_WhereSelector(item)) observer.OnNext(item); };
            return observer;
        }
    }
}